<template>
    <div class="count">
        <h2>Current sum: {{ sum }}, X 10: {{ bigSum }}</h2>
        <h3>School: {{ school }}, uppercase: {{ upperSchool }}</h3>
        <h3>Address: {{ address }}</h3>
        <select v-model.number="n">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <button @click="add">add</button>
        <button @click="subtract">subtract</button>
    </div>
</template>

<script setup lang="ts" name="Cout">
    import { reactive, ref } from 'vue'
    import { useCountStore } from '@/store/count'
    import { storeToRefs } from 'pinia';

    const countStore = useCountStore()
    // storeToRefs 只关注数据
    const {sum, school, address, bigSum, upperSchool} = storeToRefs(countStore)

    // let obj = reactive({
    //     a: 1,
    //     c: 1,
    //     d: ref(1),
    // })
    // let x = ref(10)
    // console.log(obj.a);
    // console.log(obj.c);
    // console.log(obj.d);
    
    let n = ref(1)

    function add() {
        // s1
        // countStore.sum += 1

        //s2
        // countStore.$patch({
        //     sum: 999,
        //     school: 'pku',
        //     address: 'Bj'
        // })

        // s3
        countStore.increment(n.value)
    }

    function subtract() {
        countStore.sum -= n.value
    }
</script>

<style scoped>
    .count {
        background-color: skyblue;
        padding: 10px;
        border-radius: 10px;
        box-shadow: 0 0 10px;
    }
    select, button {
        margin: 0 5px;
        height: 25px;
    }
</style>